package com.run.runbbs.job;


import com.run.runbbs.service.IndexValueService;
import com.run.runbbs.service.UserInfoService;
import com.run.runbbs.util.MailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;


@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class IndexMonitorJob {
    @Autowired
    private IndexValueService indexValueService;
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private MailUtils mailUtils;

//    //3.添加定时任务
////    @Scheduled(cron = "0/5 * * * * ?")
//    //或直接指定时间间隔，例如：15000秒
//    @Scheduled(fixedRate=15000000)
//    private void configureTasks() {
//        List<IndexValue> list=indexValueService.getAbnormalTemperature();
//        List<AbnormalIndexDto> res=new ArrayList<>();
//        for(IndexValue indexValue : list){
//            AbnormalIndexDto abnormalIndexDto=new AbnormalIndexDto();
//            BeanUtils.copyProperties(indexValue,abnormalIndexDto);
//            UserInfo userInfo=userInfoService.getOne(new QueryWrapper<UserInfo>().eq("user_id",indexValue.getUserId()));
//            BeanUtils.copyProperties(userInfo,abnormalIndexDto);
//            abnormalIndexDto.setAddress(userInfo.getAddress());
//            abnormalIndexDto.setRealname(userInfo.getRealname());
//
//            res.add(abnormalIndexDto);
//        }
//        mailUtils.sendSimpleMail("44014815@qq.com","异常数据警告","有"+res.size()+"条异常数据，请前往后台查看！");
//    }
}
